<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <home></home>
  </div>

  <template id="tpl">
    <div>
      <h2>我是home页</h2>
      {{msg}}
      <common-head 
        @biubiubiu="fn"
        @piupiupiu="fn2"
      ></common-head>
    </div>
  </template>

  <script src="./vue.js"></script>
  <script>
    const CommonHead = {
      template:`
        <div>
         <button @click="emit">按钮1</button>
         <button @click="emit2">按钮2</button>
        </div>
      `,
      data(){
        return {
          msg: '我是子组件的数据'
        }
      },
      methods: {
        emit(){
          // 触发一个自定义的事件
          this.$emit('biubiubiu')
        },
        emit2(){
          // 参数2  是事件触发 携带的参数
          this.$emit('piupiupiu', this.msg)
        }
      }
    }

    const Home = {
      template:"#tpl",
      components:{
        CommonHead
      },
      data(){
        return {
          msg:''
        }
      },
      methods: {
        fn(){
          alert("我收到了")
        },
        fn2(msg){
          this.msg = msg
        }
      }
    }
    Vue.component('Home', Home)
  
    const vm = new Vue({
      el:'#app'
    })
  </script>
</body>
</html>